﻿using shenghua.Common.CustomValueType;
using shenghua.Payment.Payments;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Payment.ThirdParties
{
    public interface IThirdPartyPaymentManagerBase
    {
        /// <summary>
        /// 生成支付跳转页面
        /// </summary>
        PaymentPageResult GeneratePaymentPage(PaymentPageParams paras);

        /// <summary>
        /// 支付同步回调
        /// </summary>
        PaymentReturnResult PaymentReturn(PaymentReturnParams paras);

        /// <summary>
        /// 支付异步回调
        /// </summary>
        PaymentNotifyResult PaymentNotify(PaymentNotifyParams paras);

        /// <summary>
        /// 查询支付状态
        /// </summary>
        PaymentQueryResult PaymentQuery(PaymentQueryParams paras);

        /// <summary>
        /// 退款
        /// </summary>
        RefundResult Refund(RefundParams paras);

        /// <summary>
        /// 退款查询
        /// </summary>
        RefundQueryResult RefundQuery(RefundQueryParams paras);

        /// <summary>
        /// 关闭交易
        /// </summary>
        CloseResult Close(CloseParams paras);
    }

    #region 参数
    public class PaymentParamsBase
    {
        public string OrderNumber { get; set; }
        public string TradeNumber { get; set; }
    }

    public class PaymentPageParams : PaymentParamsBase
    {
        public double TotalAmount { get; set; }
        public string Subject { get; set; }
        public string Description { get; set; }
        /// <summary>
        /// 同步回调地址，当付款成功时调用。字段可能已作废
        /// </summary>
        public string ReturnUrl { get; set; }
        /// <summary>
        /// 异步回调地址，当支付状态更新时由付款平台主动调用。字段可能已作废
        /// </summary>
        public string NotifyUrl { get; set; }

        public string appendUrl { get; set; }
    }

    public class PaymentReturnParams : PaymentParamsBase
    {
        public Dictionary<string, string> Request { get; set; }
    }

    public class PaymentNotifyParams : PaymentParamsBase
    {
        public Dictionary<string, string> Request { get; set; }
    }

    public class PaymentQueryParams : PaymentParamsBase
    {

    }

    public class RefundParams : PaymentParamsBase
    {
        public double RefundAmount { get; set; }
        public string RefundReason { get; set; }
        /// <summary>
        /// 退款单号，同一笔多次退款需要保证唯一，部分退款该参数必填。
        /// </summary>
        public string RefundNumber { get; set; }
    }

    public class RefundQueryParams : PaymentParamsBase
    {
        public string RefundNumber { get; set; }
    }

    public class CloseParams : PaymentParamsBase
    {

    }
    #endregion

    #region 结果
    public class PaymentResultBase
    {
        public bool Success { get; set; }
        public string Body { get; set; }
    }

    public class PaymentPageResult : PaymentResultBase
    {

    }

    public class PaymentReturnResult : PaymentResultBase
    {
        public bool IsPaid { get; set; }
        public string OrderNumber { get; set; }
        public string TradeNumber { get; set; }
        public double TotalAmount { get; set; }
    }

    public class PaymentNotifyResult : PaymentResultBase
    {
        public bool IsPaid { get; set; }
        public string OrderNumber { get; set; }
        public string TradeNumber { get; set; }
        public double TotalAmount { get; set; }
    }

    public class PaymentQueryResult : PaymentResultBase
    {

    }

    public class RefundResult : PaymentResultBase
    {

    }

    public class RefundQueryResult : PaymentResultBase
    {

    }

    public class CloseResult : PaymentResultBase
    {

    }
    #endregion
}
